<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <div id="qrcode"></div>
  <button onclick="downloadIamge()">下载二维码</button>
</body>
<script src="./qrcode.js"></script>
<script>
  var qrcode = document.getElementById('qrcode')

  /*直接生成二维码*/
  // new QRCode(qrcode, 'http://www.baidu.com')

  /*也可以配置二维码的宽高等*/
  var qrcodeObj = new QRCode('qrcode', {
    // text: 'http://www.daqianduan.com', //调用二维码生成函数,拼接参数?
    title: 'hahah',
    width: 80,
    height: 80,
    colorDark: '#000000', //前景色
    colorLight: '#ffffff' //背景色

  })
  qrcodeObj.makeCode(`asdd
  asdasd
  sadsd
  asdasd`)

  function downloadIamge() {
    var imgs = document.getElementById("qrcode").getElementsByTagName("img")
    var a = document.createElement('a')
    a.download = 'xds' + new Date().getTime() || '下载图片名称'
    a.href = imgs[0].src
    document.body.appendChild(a);
    a.click();
    document.body.removeChild(a);
  }
</script>

</html>